//
// Created by hjie on 23-7-6.
//
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>

void ProducerData(std::vector<int> & data, int number)
{
    srand(time(NULL));
    for (int index = 0; index < number; index++)
    {
        data.push_back(rand()%20);
    }
    std::sort(data.begin(), data.end());
    printf("%s : ", __func__ );
    for (auto & item : data)
    {
        printf("%d ", item);
    }
    printf("\n");
}

void DeleteRepeatNumber()
{
    int number = 30;
    std::vector<int> number_data;
    ProducerData(number_data, number);
    int * array = &(*number_data.begin());

    int slow_index = 0;
    for (int fast_index = 1; fast_index < number; fast_index++)
    {
        if (array[slow_index] == array[fast_index])
        {
            array[fast_index] = INT16_MIN;
        }
        else
        {
            slow_index = fast_index;
        }
    }
    slow_index = 0;
    for (int fast_index = 0; fast_index < number; fast_index++)
    {
        if (array[fast_index] != INT16_MIN)
        {
            array[slow_index] = array[fast_index];
            slow_index++;
        }
    }
    printf("result  data : ");
    for (auto & item : number_data)
    {
        printf("%d ", item);
    }
    printf("\n k = %d\n", (slow_index));
}

int main(int argc, const char * argv[])
{
    DeleteRepeatNumber();
    return 0;
}

